<template>
	<jk-dialog
		v-model="showDialog"
		title="详情-入库明细"
		width="800px"
		:show-content-loading="showLoading"
		append-to-body
		:show-close-btn="true"
		:show-confirm-btn="false"
		:show-cancel-btn="false"
		@on-close="onVisibleChange(false)"
		@on-visible-change="onVisibleChange"
	>
		<el-form ref="ruleForm" :model="ruleForm" label-width="100px" :show-message="false">
			<div ref="box1" class="margin-bottom-4 flex-between-center">
				<el-tag type="primary" effect="plain" class="">
					<span class="el-icon-tickets item-gap"></span>
					<span>基本信息</span>
				</el-tag>
				<div style="font-size: 14px;">
					<span class="el-icon-tickets item-gap"></span>
					<span>{{ ruleForm.saleOrderCode }}</span>
				</div>
			</div>
			<jk-card ref="box2" class="margin-bottom-10">
				<el-row class="flex-start-center-wrap">
					<el-col :span="12">
						<el-form-item class="margin-bottom-10" label="客户">
							<span class="read-only-2">{{ ruleForm.saleOrderCustomerName || '无' }}</span>
						</el-form-item>
					</el-col>
					<el-col :span="12">
						<el-form-item class="margin-bottom-10" label="品种">
							<span class="read-only-2">{{ ruleForm.productName || '无' }}</span>
						</el-form-item>
					</el-col>
					<el-col :span="12">
						<el-form-item class="margin-bottom-0" label="批号">
							<span class="read-only-2">{{ ruleForm.batchCode || '无' }}</span>
						</el-form-item>
					</el-col>
					<el-col :span="12">
						<el-form-item class="margin-bottom-0" label="销售数量">
							<span class="read-only-2">{{ `${ ruleForm.productQty || 0 } ${ ruleForm.unitName }` }}</span>
						</el-form-item>
					</el-col>
				</el-row>
			</jk-card>
			<jk-table class="" border :stripe="false" :loading="tableLoading" :data="tableData" :height="dialogTableHeight - 20">
				<vxe-column title="入库日期" align="left" field="belongDate" :width="110" />
				<vxe-column title="入库件数" align="right" field="inum" :width="100"></vxe-column>
				<vxe-column title="入库重量" align="right" field="quantity" :width="100"></vxe-column>
				<vxe-column title="单位" align="left" field="unitName" :width="90"></vxe-column>
				<vxe-column title="入库货位" align="left" field="warehouseName" :min-width="170" />
				<vxe-column title="入库单号" align="left" field="code" :width="150" />
			</jk-table>
		</el-form>
	</jk-dialog>
</template>

<script>

    import { productionSaleOrderInHistoryList } from '../../../api/production/productionMonitor';
    import calHeight from '../../../mixins/cal-dialog-height';
    export default {
        mixins: [calHeight],
        props: {
            dialogState: {
                type: Boolean,
                default: false
            },
            dataItem: {
                type: Object,
                default() {
                    return {};
                }
            },
            belongDate: {
                type: Array,
                default: () => []
            }
        },
        data() {
            return {
                tableData: [],
                tableLoading: false,
                showDialog: false,
                showLoading: false,
                ruleForm: {}
            };
        },
        methods: {
            onVisibleChange(e) {
                this.$emit('on-visible-change', e);
                if (!e) {
                    Object.assign(this.$data, this.$options.data());
                    this.$nextTick(() => {
                        this.$refs.ruleForm.resetFields();
                    });
                }
            },
            getDetailRequest() {
                this.showLoading = true;
                return productionSaleOrderInHistoryList({
                    saleOrderCode: this.dataItem.saleOrderCode,
                    // batchCode: this.dataItem.batchCode,
                    productCode: this.dataItem.productCode,
                    startDate: this.belongDate[0],
                    endDate: this.belongDate[1]
                }).then(res => {
                    this.showLoading = false;
                    if (res.data.status === 200) {
                        this.tableData = res.data.res || [];
                    }
                });
            }
        },
        watch: {
            dialogState(newVal) {
                this.showDialog = newVal;
                if (newVal) {
                    this.ruleForm = this.dataItem ? JSON.parse(JSON.stringify(this.dataItem)) : {};
                    this.getDetailRequest();
                }
            }
        }
    };
</script>
